import {
  reqCategoryList,
  reqGetBannerList,
  reqGetFloorList,
} from '../../api/index'
// home模块小仓库
const state = {
  CategoryList: [],
  bannerList: [],
  floorlist: [],
}
// mutations是唯一修改state地方
const mutations = {
  CATEGORYLIST(state, CategoryList) {
    state.CategoryList = CategoryList
  },
  GETBANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  GETFLOORLIST(state, floorlist) {
    state.floorlist = floorlist
  },
}
// actions|用户处理派发actions地方，可以书写异步语句，自己逻辑地方
const actions = {
  async CategoryList({ commit }) {
    let result = await reqCategoryList()
    if (result.code === 200) {
      commit('CATEGORYLIST', result.data)
    }
  },
  // 获取首页轮播图数据
  async getBannerList({ commit }) {
    let result = await reqGetBannerList()
    if (result.code === 200) {
      commit('GETBANNERLIST', result.data)
    }
  },
  // 获取floor数据
  async getFloorList({ commit }) {
    let result = await reqGetFloorList()
    if (result.code === 200) {
      commit('GETFLOORLIST', result.data)
    }
  },
}
// 计算属性
const getters = {}
// 导出
export default {
  state,
  mutations,
  actions,
  getters,
}
